#!/bin/bash

# 进入源代码文件夹
cd /opt/auto_publish/source

chmod a+x -R  spring-boot-docker
cd spring-boot-docker/

#git接取最新的代码
git reset --hard
git checkout
git pull origin master

 
 echo git finished

#获取当前版本的标识
#GIT_SHORT_CODE = git rev-parse --short HEAD


#编译java项目  直接在父级
mvn clean  install -Dmaven.test.skip=true

echo mvn finished

#重命名并复制到发布目录  这个目录下可能有自己的配置文件
rm -rf /opt/auto_publish/publish/spring-boot-docker/spring-boot-docker.jar
cp -a target/spring-boot-docker.jar /opt/auto_publish/publish/spring-boot-docker

echo cp finished

#杀死占用某个端口的进程
#查杀
PID=$(ps -ef | grep spring-boot-docker.jar | grep -v grep | awk '{ print $2 }')
if [ -z "$PID" ]
then
    echo Application is already stopped
else
    echo kill $PID
    kill $PID
fi

echo kill old finished
#启动
nohup java -jar /opt/auto_publish/publish/spring-boot-docker/spring-boot-docker.jar > /opt/auto_publish/publish/log/spring-boot-docker.log &

echo startup finished



